Dart BigInt operator -
Syntax & Examples
BigInt.operator - operator
The `operator -` in Dart performs subtraction between two BigInt objects.
Syntax of BigInt.operator -
The syntax of BigInt.operator - operator is:
operator -(BigInt other) → BigIntThis operator - operator of BigInt subtraction operator.
Parameters
| Parameter | Optional/Required | Description |
|---|---|---|
other | required | the BigInt object to subtract |
✐ Examples
1 Subtract Positive BigInts
In this example,
- We create two BigInt objects,
num1andnum2, initialized with positive integers. - We use the
-operator to subtractnum2fromnum1. - We print the result of the subtraction to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(6);
BigInt result = num1 - num2;
print('Result of subtraction: $result');
}Output
Result of subtraction: 4
2 Subtract Positive BigInts (larger number first)
In this example,
- We create two BigInt objects,
num1andnum2, initialized with positive integers. - We use the
-operator to subtractnum2fromnum1. - We print the result of the subtraction to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(100);
BigInt num2 = BigInt.from(50);
BigInt result = num1 - num2;
print('Result of subtraction: $result');
}Output
Result of subtraction: 50
3 Subtract Positive BigInts (negative result)
In this example,
- We create two BigInt objects,
num1andnum2, initialized with positive integers. - We use the
-operator to subtractnum2fromnum1. - We print the result of the subtraction to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(5);
BigInt num2 = BigInt.from(10);
BigInt result = num1 - num2;
print('Result of subtraction: $result');
}Output
Result of subtraction: -5
Summary
In this Dart tutorial, we learned about operator - operator of BigInt: the syntax and few working examples with output and detailed explanation for each example.